<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 李邦琦 <1536549251@qq.com>
// +----------------------------------------------------------------------

namespace app\crm\model;
use think\Db;
use think\Model;
use think\Cache;

class Checkwork extends Model
{
    /**
     * 获取打卡列表
     * @param str $where <查询条件>
     * @param int $page <页码>
     * @param int $limit <每页显示条数>
     * @return array <日报列表信息>
     */
    public function getCheckWorkData($where,$page,$limit)
    {
        $count = Db::name('mob_sign')->where($where)->count();
        // 查询状态为1的用户数据 并且每页显示10条数据
        $checkWorkList = Db::name('mob_sign')->where($where)->limit(($page-1)*$limit,$limit)->order('signtime DESC')->select();
        $users = Cache::get('users');
        foreach ($checkWorkList as &$val) {
            switch ($val['signout']) {
                case '1': $val['signout'] = '签到'; break;
                case '2': $val['signout'] = '签退'; break;
            }
            $val['details_place'] = $val['place'].' '.$val['sematic_description'];
            $val['username'] = $users[$val['username']]['cn_name'];
        }
        $rowsList = count($checkWorkList) ? $checkWorkList : false;
        $arrData["code"] = 0;
        $arrData["msg"] = '';
        $arrData["count"] = $count;
        $arrData["data"] = $rowsList;
        return $arrData;
    }


}